//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class TableGrid : IOfficeXmlSerializable
    {
        private const string xmlName = "tblGrid";
        private readonly List<TableColumn> gridCol = new List<TableColumn>();

        #region IOfficeXmlSerializable Members

        /// <summary>
        /// Generates an object from its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read(xmlName))
            {
                gridCol.Clear();
                gridCol.AddRange(c.ReadOptionalWhile<TableColumn>(TableColumn.xmlName));
            }
        }

        /// <summary>
        /// Convert an object into its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write(xmlName))
            {
                c.WriteElements(gridCol);
            }
        }

        #endregion
    }
}